/*********************\
* Author:Dzlua
* QQ:505544956
* Time:2017/04/16
\**********************/
#include "LuaWebBrowser.h"

#define CObjPtr ((CWebBrowserUI*)m_cobj)

namespace DuiLib {

int LuaWebBrowser::GetHomePage(LuaState *L)
{
    SDTString str = CObjPtr->GetHomePage();
    LuaHelperNS::PushTString(L, str);
    return 1;
}

int LuaWebBrowser::SetHomePage(LuaState *L)
{
    LuaStack args(L);
    SDTString str = LuaHelperNS::GetTString(args[2]);
    CObjPtr->SetHomePage(str.c_str());
    return 0;
}

void LuaWebBrowser::SetAutoNavigation(bool bAuto)
{
    CObjPtr->SetAutoNavigation(bAuto);
}

bool LuaWebBrowser::IsAutoNavigation()
{
    return CObjPtr->IsAutoNavigation();
}

int LuaWebBrowser::Navigate2(LuaState *L)
{
    LuaStack args(L);
    SDTString str = LuaHelperNS::GetTString(args[2]);
    CObjPtr->Navigate2(str.c_str());
    return 0;
}

void LuaWebBrowser::Refresh()
{
    CObjPtr->Refresh();
}

void LuaWebBrowser::Refresh2(int Level)
{
    CObjPtr->Refresh2(Level);
}

void LuaWebBrowser::GoBack()
{
    CObjPtr->GoBack();
}

void LuaWebBrowser::GoForward()
{
    CObjPtr->GoForward();
}

void LuaWebBrowser::NavigateHomePage()
{
    CObjPtr->NavigateHomePage();
}

int LuaWebBrowser::NavigateUrl(LuaState *L)
{
    LuaStack args(L);
    SDTString str = LuaHelperNS::GetTString(args[2]);
    CObjPtr->NavigateUrl(str.c_str());
    return 0;
}

bool LuaWebBrowser::DoCreateControl()
{
    return CObjPtr->DoCreateControl();
}

SDLUA_BEGIN_REGISTER(LuaWebBrowser, WebBrowser, ActiveX)
    SDLUA_REGISTER_FUN_LUA(LuaWebBrowser, GetHomePage, GetHomePage)
    SDLUA_REGISTER_FUN_LUA(LuaWebBrowser, SetHomePage, SetHomePage)

    SDLUA_REGISTER_FUN_CPP(LuaWebBrowser, SetAutoNavigation, SetAutoNavigation)
    SDLUA_REGISTER_FUN_CPP(LuaWebBrowser, IsAutoNavigation, IsAutoNavigation)

    SDLUA_REGISTER_FUN_LUA(LuaWebBrowser, Navigate2, Navigate2)
    SDLUA_REGISTER_FUN_CPP(LuaWebBrowser, Refresh, Refresh)
    SDLUA_REGISTER_FUN_CPP(LuaWebBrowser, Refresh2, Refresh2)
    SDLUA_REGISTER_FUN_CPP(LuaWebBrowser, GoBack, GoBack)
    SDLUA_REGISTER_FUN_CPP(LuaWebBrowser, GoForward, GoForward)
    SDLUA_REGISTER_FUN_CPP(LuaWebBrowser, NavigateHomePage, NavigateHomePage)
    SDLUA_REGISTER_FUN_LUA(LuaWebBrowser, NavigateUrl, NavigateUrl)

    SDLUA_REGISTER_FUN_CPP(LuaWebBrowser, DoCreateControl, DoCreateControl)

SDLUA_END_REGISTER

SDLUA_BEGIN_UNREGISTER(LuaWebBrowser, WebBrowser)
SDLUA_END_UNREGISTER(WebBrowser)

}

#undef CObjPtr